package com.dhl.springbootrabbitmq.listening;

import com.dhl.springbootrabbitmq.config.ConfirmConfig;
import com.dhl.springbootrabbitmq.config.TtlQueueConfig;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * rabbit监听器
 * @author danghailiang
 */
@Slf4j
@Component
public class RabbitConfirmListening {
    /**
     * 监听对列
     *
     * @param message
     * @param channel
     */
    @RabbitListener(queues = ConfirmConfig.CONFIRM_QUEUE_NAME)
    public void receiveD(Message message, Channel channel) {
        log.info("高级确认练习：交换机：{},接收到的数据是：{}", ConfirmConfig.CONFIRM_EXCHANGE_NAME, new String(message.getBody(), StandardCharsets.UTF_8));
    }

    /**
     * 报警消费者监听对列
     * @param message
     * @param channel
     */
    @RabbitListener(queues = ConfirmConfig.BACKUP_QUEUE_NAME)
    public void receiveBackupD(Message message, Channel channel) {
        log.warn("高级确认练习：备用交换机：{},接收到的数据是：{}", ConfirmConfig.BACKUP_EXCHANGE_NAME, new String(message.getBody(), StandardCharsets.UTF_8));
    }
}